﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace MikroTransfer
{
    public enum EvrakTipleri : byte
    {
        SatisFaturasi = 0,
        AlisFaturasi = 1,
        AlisIrsaliyesi = 2,
        DepoSevk = 3,
        GelenHavale = 4,
        GidenHavale = 5
    }

    public enum HesapTipi : byte
    {
        Cari = 0,
        Banka = 2,
        Kasa = 4,
        Masraf = 5
    }

    public class Mikro
    {
        private DbSqlServer _dbsql;
        private Db _dbSystem;
        public Mikro(Db dbSystem)
        {
            _dbSystem = dbSystem;
            _dbsql = new DbSqlServer(dbSystem);
        }

        public virtual int[] SharEvrakTip(EvrakTipleri evrakTip)
        {
            int[] sonuc = new int[4];
            switch (evrakTip)
            {
                case EvrakTipleri.SatisFaturasi:
                    sonuc[0] = 1;
                    sonuc[1] = 0;
                    sonuc[2] = 0;
                    sonuc[3] = 4;
                    break;
                case EvrakTipleri.AlisFaturasi:
                    sonuc[0] = 0;
                    sonuc[1] = 0;
                    sonuc[2] = 0;
                    sonuc[3] = 3;
                    break;
                case EvrakTipleri.AlisIrsaliyesi:
                    sonuc[0] = 0;
                    sonuc[1] = 0;
                    sonuc[2] = 0;
                    sonuc[3] = 13;
                    break;
                case EvrakTipleri.DepoSevk:
                    sonuc[0] = 2;
                    sonuc[1] = 6;
                    sonuc[2] = 0;
                    sonuc[3] = 2;
                    break;
                default:
                    break;
            }
            return sonuc;
        }

        public virtual int[] CharEvrakTip(EvrakTipleri evrakTip)
        {
            int[] sonuc = new int[4];
            switch (evrakTip)
            {
                case EvrakTipleri.SatisFaturasi:
                    sonuc[0] = 0;
                    sonuc[1] = 6;
                    sonuc[2] = 0;
                    sonuc[3] = 63;
                    break;
                case EvrakTipleri.AlisFaturasi:
                    sonuc[0] = 1;
                    sonuc[1] = 6;
                    sonuc[2] = 0;
                    sonuc[3] = 0;
                    break;
                case EvrakTipleri.GelenHavale:
                    sonuc[0] = 1;
                    sonuc[1] = 0;
                    sonuc[2] = 0;
                    sonuc[3] = 34;
                    break;
                case EvrakTipleri.GidenHavale:
                    sonuc[0] = 0;
                    sonuc[1] = 0;
                    sonuc[2] = 0;
                    sonuc[3] = 35;
                    break;
            }
            return sonuc;
        }

        public virtual void SerinoHareketEkle(string seriNo, string stokKodu, int sharId, DateTime garantiBaslangic, DateTime garantiBitis, DateTime alisTarihi, DateTime satisTarihi, string alisSeri, int alisSira, string satisSeri, int satisSira, decimal alisFiyat, decimal satisFiyat, string alisCari, string satisCari, SqlTransaction trn)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("if exists(select ChHar_RECno from CIHAZ_HAREKETLERI where ChHar_SeriNo= @seriNo and ChHar_StokKodu=@stokKodu and ChHar_master_recno=@sharId)");
            sb.Append("update CIHAZ_HAREKETLERI set ChHar_Spec_Rec_no=0,ChHar_iptal=0,ChHar_fileid=98,ChHar_hidden=0,ChHar_kilitli=0,ChHar_degisti=0,ChHar_checksum=0,ChHar_lastup_user=1,ChHar_lastup_date=@tarih,ChHar_special1='',ChHar_special2='',ChHar_special3='',ChHar_master_tablo=0,ChHar_master_dbcno=0 where ChHar_SeriNo=@seriNo and ChHar_StokKodu=@stokKodu and ChHar_master_recno=@sharId else ");
            sb.Append("insert into CIHAZ_HAREKETLERI (ChHar_RECid_DBCno,ChHar_RECid_RECno,ChHar_Spec_Rec_no,ChHar_iptal,ChHar_fileid,ChHar_hidden,ChHar_kilitli,ChHar_degisti,ChHar_checksum,ChHar_create_user,ChHar_create_date,ChHar_lastup_user,ChHar_lastup_date,ChHar_special1,ChHar_special2,ChHar_special3,ChHar_SeriNo,ChHar_StokKodu,ChHar_master_tablo,ChHar_master_dbcno,ChHar_master_recno) values (0,-1,0,0,98,0,0,0,0,1,@tarih,1,@tarih,'','','',@seriNo,@stokKodu,0,0,@sharId) ");
            sb.Append(";update CIHAZ_HAREKETLERI set ChHar_RECid_RECno=ChHar_RECno where ChHar_RECid_RECno=-1");

            StringBuilder sb2 = new StringBuilder();
            sb2.Append("if exists(select chz_RECno from STOK_SERINO_TANIMLARI where chz_serino= @seriNo and chz_stok_kodu=@stokKodu)");
            sb2.Append("UPDATE    STOK_SERINO_TANIMLARI SET chz_Spec_Rec_no = 0, chz_iptal = 0, chz_fileid = 94, chz_hidden = 0, chz_kilitli = 0, chz_degisti = 0, chz_checksum = 0, chz_lastup_user = 1, chz_lastup_date = @tarih, chz_special1 = '', chz_special2 = '', chz_special3 = '', chz_Tuktckodu = '', chz_GrnBasTarihi = @garantiBaslangic,chz_GrnBitTarihi = @garantiBitis, chz_aciklama1 = '', chz_aciklama2 = '', chz_aciklama3 = '', chz_al_tarih = @alisTarih, chz_al_evr_seri = @alisSeri,chz_al_evr_sira = @alisSira, chz_st_tarih = @satisTarih, chz_st_evr_seri = @satisSeri, chz_st_evr_sira = @satisSira, chz_al_fiati_ana = @alisFiyat,chz_al_fiati_alt = @alisFiyat, chz_al_fiati_orj = @alisFiyat, chz_st_fiati_ana = @satisFiyat, chz_st_fiati_alt = @satisFiyat, chz_st_fiati_orj = @satisFiyat,chz_parca_garantisi = 0, chz_parca_serino = '', chz_parca_garanti_baslangic = @garantiBaslangic, chz_parca_garanti_bitis = @garantiBitis,chz_al_cari_kodu = @alisCari, chz_st_cari_kodu = @satisCari WHERE (chz_serino = @seriNo) AND (chz_stok_kodu = @stokKodu) else ");
            sb2.Append("INSERT INTO STOK_SERINO_TANIMLARI (chz_RECid_DBCno, chz_RECid_RECno, chz_Spec_Rec_no, chz_iptal, chz_fileid, chz_hidden, chz_kilitli, chz_degisti, chz_checksum, chz_create_user,chz_create_date, chz_lastup_user, chz_lastup_date, chz_special1, chz_special2, chz_special3, chz_serino, chz_stok_kodu, chz_grup_kodu, chz_Tuktckodu,chz_GrnBasTarihi, chz_GrnBitTarihi, chz_aciklama1, chz_aciklama2, chz_aciklama3, chz_al_tarih, chz_al_evr_seri, chz_al_evr_sira, chz_al_cari_kodu, chz_st_tarih,chz_st_evr_seri, chz_st_evr_sira, chz_st_cari_kodu, chz_al_fiati_ana, chz_al_fiati_alt, chz_al_fiati_orj, chz_st_fiati_ana, chz_st_fiati_alt, chz_st_fiati_orj,chz_parca_garantisi, chz_parca_serino, chz_parca_garanti_baslangic, chz_parca_garanti_bitis) VALUES (0, - 1, 0, 0, 94, 0, 0, 0, 0, 1,@tarih, 1,@tarih, '', '', '',@seriNo,@stokKodu, '', '',@garantiBaslangic,@garantiBitis, '', '','',@alisTarih,@alisSeri,@alisSira,@alisCari,@satisTarih,@satisSeri,@satisSira,@satisCari,@alisFiyat,@alisFiyat,@alisFiyat,@satisFiyat,@satisFiyat,@satisFiyat,0,'',@garantiBaslangic,@garantiBitis) ");
            sb2.Append(";update STOK_SERINO_TANIMLARI set chz_RECid_RECno=chz_RECno where chz_RECid_RECno=-1");

            List<SqlParameter> prmList = new List<SqlParameter>();
            prmList.Add(new SqlParameter() { ParameterName = "@seriNo", SqlDbType = SqlDbType.VarChar, Size = 25, Value = seriNo });
            prmList.Add(new SqlParameter() { ParameterName = "@stokKodu", SqlDbType = SqlDbType.VarChar, Size = 25, Value = stokKodu });
            prmList.Add(new SqlParameter() { ParameterName = "@sharId", SqlDbType = SqlDbType.Int, Value = sharId });
            prmList.Add(new SqlParameter() { ParameterName = "@tarih", SqlDbType = SqlDbType.DateTime, Value = DateTime.Now });
            _dbsql.Exec(sb.ToString(), trn, prmList.ToArray());


            prmList.Add(new SqlParameter() { ParameterName = "@alisSeri", SqlDbType = SqlDbType.VarChar, Size = 6, Value = alisSeri });
            prmList.Add(new SqlParameter() { ParameterName = "@alisSira", SqlDbType = SqlDbType.Int, Value = alisSira });
            prmList.Add(new SqlParameter() { ParameterName = "@satisSeri", SqlDbType = SqlDbType.VarChar, Size = 6, Value = satisSeri });
            prmList.Add(new SqlParameter() { ParameterName = "@satisSira", SqlDbType = SqlDbType.Int, Value = satisSira });
            prmList.Add(new SqlParameter() { ParameterName = "@alisFiyat", SqlDbType = SqlDbType.Float, Value = alisFiyat });
            prmList.Add(new SqlParameter() { ParameterName = "@satisFiyat", SqlDbType = SqlDbType.Float, Value = satisFiyat });
            prmList.Add(new SqlParameter() { ParameterName = "@alisTarih", SqlDbType = SqlDbType.DateTime, Value = alisTarihi });
            prmList.Add(new SqlParameter() { ParameterName = "@satisTarih", SqlDbType = SqlDbType.DateTime, Value = satisTarihi });
            prmList.Add(new SqlParameter() { ParameterName = "@garantiBaslangic", SqlDbType = SqlDbType.DateTime, Value = garantiBaslangic });
            prmList.Add(new SqlParameter() { ParameterName = "@garantiBitis", SqlDbType = SqlDbType.DateTime, Value = garantiBitis });
            prmList.Add(new SqlParameter() { ParameterName = "@alisCari", SqlDbType = SqlDbType.VarChar, Size = 25, Value = alisCari });
            prmList.Add(new SqlParameter() { ParameterName = "@satisCari", SqlDbType = SqlDbType.VarChar, Size = 25, Value = alisCari });

            _dbsql.Exec(sb2.ToString(), trn, prmList.ToArray());
        }

        public virtual void HavaleEkle(bool gelenHavale, SqlTransaction trn, DateTime tarih, string bankaKodu, HesapTipi tip, string karsiHesapKodu, decimal meblag, string aciklama, string srmKodu, string seri, int sira, int satir, string karsiSrm)
        {
            List<SqlParameter> prmList = new List<SqlParameter>();
            StringBuilder sb = new StringBuilder();
            sb.Append("if exists(select cha_RECno from CARI_HESAP_HAREKETLERI where cha_evrak_tip=@cha_evrak_tip and cha_satir_no=@cha_satir_no and cha_evrakno_seri=@cha_evrakno_seri and cha_evrakno_sira=@cha_evrakno_sira )");
            sb.Append("update CARI_HESAP_HAREKETLERI set cha_SpecRecNo=0,cha_iptal=0,cha_fileid=51,cha_hidden=0,cha_kilitli=0,cha_degisti=0,cha_CheckSum=0,cha_create_user=1,cha_create_date=@cha_create_date,cha_lastup_user=1,cha_lastup_date=@cha_lastup_date,cha_special1='',cha_special2='',cha_special3='',cha_firmano=0,cha_subeno=0,cha_tarihi=@cha_tarihi,cha_tip=@cha_tip,cha_cinsi=0,cha_normal_Iade=0,cha_belge_no=@cha_belge_no,cha_belge_tarih=@cha_belge_tarih,cha_cari_cins=@cha_cari_cins,cha_kod=@cha_kod,cha_kasa_hizmet=2,cha_kasa_hizkod=@cha_kasa_hizkod,cha_d_kurtar='1899-12-30 00:00:00',cha_d_cins=0,cha_d_kur=1,cha_altd_kur=1,cha_grupno=@cha_grupno,cha_meblag=@cha_meblag,cha_vade=@cha_vade,cha_fis_tarih='1899-12-30 00:00:00',cha_fis_sirano=0,cha_ft_iskonto1=0,cha_ft_iskonto2=0,cha_ft_iskonto3=0,cha_ft_iskonto4=0,cha_ft_iskonto5=0,cha_ft_iskonto6=0,cha_ft_masraf1=0,cha_ft_masraf2=0,cha_ft_masraf3=0,cha_ft_masraf4=0,cha_vergi1=0,cha_vergi2=0,cha_vergi3=0,cha_vergi4=0,cha_vergi5=0,cha_vergi6=0,cha_vergi7=0,cha_vergi8=0,cha_vergi9=0,cha_vergi10=0,cha_yuvarlama=0,cha_tpoz=0,cha_aciklama=@cha_aciklama,cha_trefno='',cha_sntck_poz=0,cha_karsidcinsi=0,cha_karsid_kur=1,cha_karsidgrupno=1,cha_srmrkkodu=@cha_srmrkkodu,cha_reftarihi='1899-12-30 00:00:00',cha_odeme_arr1=0,cha_odeme_arr2=0,cha_odeme_arr3=0,cha_odeme_arr4=0,cha_odeme_arr5=0,cha_odeme_arr6=0,cha_odeme_arr7=0,cha_odeme_arr8=0,cha_miktari=0,cha_aratoplam=@cha_aratoplam,cha_vergipntr=0,cha_istisnakodu=0,cha_ver_tev_carpani=0,cha_stopaj=0,cha_savsandesfonu=0,cha_vergisiz_fl=0,cha_satici_kodu='',cha_mustahsil_borsa=0,cha_mustahsil_bagkur=0,cha_mustahsil_diger=0,cha_HalMSDF=0,cha_HalHamaliye=0,cha_HalStopaj=0,cha_HalKomisyonu=0,cha_StFonPntr=0,cha_pos_hareketi=0,cha_vardiya_tarihi='1899-12-30 00:00:00',cha_vardiya_no=0,cha_vardiya_evrak_ti=0,cha_HalRusum=0,cha_HalNavlunTut=0,cha_HalRehinFuture=0,cha_HalKomisyon=0,cha_Vade_Farki_Yuz=0,cha_karsisrmrkkodu=@cha_karsisrmrkkodu,cha_EXIMkodu='',cha_HalRehinSandikmiktari=0,cha_HalSandikVrMiktar=0,cha_HalSandikTutari=0,cha_HalSandikKDVTutari=0,cha_HalrehinSandikTutari=0,cha_Tevkifat_turu=0,cha_ticaret_turu=0,cha_otvtutari=0,cha_otvvergisiz_fl=0,cha_projekodu='',cha_sozlesme_DBCno=0,cha_sozlesme_RECno=0,cha_yat_tes_kodu='',cha_ciro_cari_kodu='',cha_oivergisiz_fl=0,cha_meblag_ana_doviz_icin_gecersiz_fl=0,cha_meblag_alt_doviz_icin_gecersiz_fl=0,cha_meblag_orj_doviz_icin_gecersiz_fl=0,cha_ciroprim_DBCno=0,cha_ciroprim_RECno=0,cha_HalHamaliyeKdv=0,cha_HalHamaliyeVergisiz_fl=0,cha_bakimhar_DBCno=0,cha_bakimhar_RECno=0,cha_avanstalep_DBCno=0,cha_avanstalep_RECno=0,cha_oiv_pntr=0,cha_oiv_vergi=0,cha_oivtutari=0,cha_isk_mas1=0,cha_isk_mas2=0,cha_isk_mas3=0,cha_isk_mas4=0,cha_isk_mas5=0,cha_isk_mas6=0,cha_isk_mas7=0,cha_isk_mas8=0,cha_isk_mas9=0,cha_isk_mas10=0,cha_sat_iskmas1=0,cha_sat_iskmas2=0,cha_sat_iskmas3=0,cha_sat_iskmas4=0,cha_sat_iskmas5=0,cha_sat_iskmas6=0,cha_sat_iskmas7=0,cha_sat_iskmas8=0,cha_sat_iskmas9=0,cha_sat_iskmas10=0,cha_sip_recid_dbcno=0,cha_sip_recid_recno=0,cha_gidkatsoz_recid_dbcno=0,cha_gidkatsoz_recid_recno=0,cha_tevkifat1Yok=0,cha_tevkifat131=0,cha_tevkifat191=0,cha_tevkifat121=0,cha_tevkifat132=0,cha_tevkifat161=0,cha_tevkifat145=0,cha_tevkifat1Tam=0,cha_tevkifat2Yok=0,cha_tevkifat231=0,cha_tevkifat291=0,cha_tevkifat221=0,cha_tevkifat232=0,cha_tevkifat261=0,cha_tevkifat245=0,cha_tevkifat2Tam=0,cha_tevkifat3Yok=0,cha_tevkifat331=0,cha_tevkifat391=0,cha_tevkifat321=0,cha_tevkifat332=0,cha_tevkifat361=0,cha_tevkifat345=0,cha_tevkifat3Tam=0,cha_tevkifat4Yok=0,cha_tevkifat431=0,cha_tevkifat491=0,cha_tevkifat421=0,cha_tevkifat432=0,cha_tevkifat461=0,cha_tevkifat445=0,cha_tevkifat4Tam=0,cha_tevkifat5Yok=0,cha_tevkifat531=0,cha_tevkifat591=0,cha_tevkifat521=0,cha_tevkifat532=0,cha_tevkifat561=0,cha_tevkifat545=0,cha_tevkifat5Tam=0,cha_tevkifat6Yok=0,cha_tevkifat631=0,cha_tevkifat691=0,cha_tevkifat621=0,cha_tevkifat632=0,cha_tevkifat661=0,cha_tevkifat645=0,cha_tevkifat6Tam=0,cha_tevkifat7Yok=0,cha_tevkifat731=0,cha_tevkifat791=0,cha_tevkifat721=0,cha_tevkifat732=0,cha_tevkifat761=0,cha_tevkifat745=0,cha_tevkifat7Tam=0,cha_tevkifat8Yok=0,cha_tevkifat831=0,cha_tevkifat891=0,cha_tevkifat821=0,cha_tevkifat832=0,cha_tevkifat861=0,cha_tevkifat845=0,cha_tevkifat8Tam=0,cha_tevkifat9Yok=0,cha_tevkifat931=0,cha_tevkifat991=0,cha_tevkifat921=0,cha_tevkifat932=0,cha_tevkifat961=0,cha_tevkifat945=0,cha_tevkifat9Tam=0,cha_tevkifat10Yok=0,cha_tevkifat1031=0,cha_tevkifat1091=0,cha_tevkifat1021=0,cha_tevkifat1032=0,cha_tevkifat1061=0,cha_tevkifat1045=0,cha_tevkifat10Tam=0 where cha_evrak_tip=@cha_evrak_tip and cha_satir_no=@cha_satir_no and cha_evrakno_seri=@cha_evrakno_seri and cha_evrakno_sira=@cha_evrakno_sira  else ");
            sb.Append("insert into CARI_HESAP_HAREKETLERI (cha_RECid_DBCno,cha_RECid_RECno,cha_SpecRecNo,cha_iptal,cha_fileid,cha_hidden,cha_kilitli,cha_degisti,cha_CheckSum,cha_create_user,cha_create_date,cha_lastup_user,cha_lastup_date,cha_special1,cha_special2,cha_special3,cha_firmano,cha_subeno,cha_tarihi,cha_tip,cha_cinsi,cha_normal_Iade,cha_evrak_tip,cha_satir_no,cha_evrakno_seri,cha_evrakno_sira,cha_belge_no,cha_belge_tarih,cha_cari_cins,cha_kod,cha_kasa_hizmet,cha_kasa_hizkod,cha_d_kurtar,cha_d_cins,cha_d_kur,cha_altd_kur,cha_grupno,cha_meblag,cha_vade,cha_fis_tarih,cha_fis_sirano,cha_ft_iskonto1,cha_ft_iskonto2,cha_ft_iskonto3,cha_ft_iskonto4,cha_ft_iskonto5,cha_ft_iskonto6,cha_ft_masraf1,cha_ft_masraf2,cha_ft_masraf3,cha_ft_masraf4,cha_vergi1,cha_vergi2,cha_vergi3,cha_vergi4,cha_vergi5,cha_vergi6,cha_vergi7,cha_vergi8,cha_vergi9,cha_vergi10,cha_yuvarlama,cha_tpoz,cha_aciklama,cha_trefno,cha_sntck_poz,cha_karsidcinsi,cha_karsid_kur,cha_karsidgrupno,cha_srmrkkodu,cha_reftarihi,cha_odeme_arr1,cha_odeme_arr2,cha_odeme_arr3,cha_odeme_arr4,cha_odeme_arr5,cha_odeme_arr6,cha_odeme_arr7,cha_odeme_arr8,cha_miktari,cha_aratoplam,cha_vergipntr,cha_istisnakodu,cha_ver_tev_carpani,cha_stopaj,cha_savsandesfonu,cha_vergisiz_fl,cha_satici_kodu,cha_mustahsil_borsa,cha_mustahsil_bagkur,cha_mustahsil_diger,cha_HalMSDF,cha_HalHamaliye,cha_HalStopaj,cha_HalKomisyonu,cha_StFonPntr,cha_pos_hareketi,cha_vardiya_tarihi,cha_vardiya_no,cha_vardiya_evrak_ti,cha_HalRusum,cha_HalNavlunTut,cha_HalRehinFuture,cha_HalKomisyon,cha_Vade_Farki_Yuz,cha_karsisrmrkkodu,cha_EXIMkodu,cha_HalRehinSandikmiktari,cha_HalSandikVrMiktar,cha_HalSandikTutari,cha_HalSandikKDVTutari,cha_HalrehinSandikTutari,cha_Tevkifat_turu,cha_ticaret_turu,cha_otvtutari,cha_otvvergisiz_fl,cha_projekodu,cha_sozlesme_DBCno,cha_sozlesme_RECno,cha_yat_tes_kodu,cha_ciro_cari_kodu,cha_oivergisiz_fl,cha_meblag_ana_doviz_icin_gecersiz_fl,cha_meblag_alt_doviz_icin_gecersiz_fl,cha_meblag_orj_doviz_icin_gecersiz_fl,cha_ciroprim_DBCno,cha_ciroprim_RECno,cha_HalHamaliyeKdv,cha_HalHamaliyeVergisiz_fl,cha_bakimhar_DBCno,cha_bakimhar_RECno,cha_avanstalep_DBCno,cha_avanstalep_RECno,cha_oiv_pntr,cha_oiv_vergi,cha_oivtutari,cha_isk_mas1,cha_isk_mas2,cha_isk_mas3,cha_isk_mas4,cha_isk_mas5,cha_isk_mas6,cha_isk_mas7,cha_isk_mas8,cha_isk_mas9,cha_isk_mas10,cha_sat_iskmas1,cha_sat_iskmas2,cha_sat_iskmas3,cha_sat_iskmas4,cha_sat_iskmas5,cha_sat_iskmas6,cha_sat_iskmas7,cha_sat_iskmas8,cha_sat_iskmas9,cha_sat_iskmas10,cha_sip_recid_dbcno,cha_sip_recid_recno,cha_gidkatsoz_recid_dbcno,cha_gidkatsoz_recid_recno,cha_tevkifat1Yok,cha_tevkifat131,cha_tevkifat191,cha_tevkifat121,cha_tevkifat132,cha_tevkifat161,cha_tevkifat145,cha_tevkifat1Tam,cha_tevkifat2Yok,cha_tevkifat231,cha_tevkifat291,cha_tevkifat221,cha_tevkifat232,cha_tevkifat261,cha_tevkifat245,cha_tevkifat2Tam,cha_tevkifat3Yok,cha_tevkifat331,cha_tevkifat391,cha_tevkifat321,cha_tevkifat332,cha_tevkifat361,cha_tevkifat345,cha_tevkifat3Tam,cha_tevkifat4Yok,cha_tevkifat431,cha_tevkifat491,cha_tevkifat421,cha_tevkifat432,cha_tevkifat461,cha_tevkifat445,cha_tevkifat4Tam,cha_tevkifat5Yok,cha_tevkifat531,cha_tevkifat591,cha_tevkifat521,cha_tevkifat532,cha_tevkifat561,cha_tevkifat545,cha_tevkifat5Tam,cha_tevkifat6Yok,cha_tevkifat631,cha_tevkifat691,cha_tevkifat621,cha_tevkifat632,cha_tevkifat661,cha_tevkifat645,cha_tevkifat6Tam,cha_tevkifat7Yok,cha_tevkifat731,cha_tevkifat791,cha_tevkifat721,cha_tevkifat732,cha_tevkifat761,cha_tevkifat745,cha_tevkifat7Tam,cha_tevkifat8Yok,cha_tevkifat831,cha_tevkifat891,cha_tevkifat821,cha_tevkifat832,cha_tevkifat861,cha_tevkifat845,cha_tevkifat8Tam,cha_tevkifat9Yok,cha_tevkifat931,cha_tevkifat991,cha_tevkifat921,cha_tevkifat932,cha_tevkifat961,cha_tevkifat945,cha_tevkifat9Tam,cha_tevkifat10Yok,cha_tevkifat1031,cha_tevkifat1091,cha_tevkifat1021,cha_tevkifat1032,cha_tevkifat1061,cha_tevkifat1045,cha_tevkifat10Tam) values (0,-1,0,0,51,0,0,0,0,1,@cha_create_date,1,@cha_lastup_date,'','','',0,0,@cha_tarihi,@cha_tip,0,0,@cha_evrak_tip,@cha_satir_no,@cha_evrakno_seri,@cha_evrakno_sira,@cha_belge_no,@cha_belge_tarih,@cha_cari_cins,@cha_kod,2,@cha_kasa_hizkod,'1899-12-30 00:00:00',0,1,1,@cha_grupno,@cha_meblag,@cha_vade,'1899-12-30 00:00:00',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,@cha_aciklama,'',0,0,1,1,@cha_srmrkkodu,'1899-12-30 00:00:00',0,0,0,0,0,0,0,0,0,@cha_aratoplam,0,0,0,0,0,0,'',0,0,0,0,0,0,0,0,0,'1899-12-30 00:00:00',0,0,0,0,0,0,0,@cha_karsisrmrkkodu,'',0,0,0,0,0,0,0,0,0,'',0,0,'','',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) ");
            sb.Append(";update CARI_HESAP_HAREKETLERI set cha_RECid_RECno=cha_RECno where cha_RECid_RECno=-1");

            prmList.Add(new SqlParameter() { ParameterName = "@cha_create_date", SqlDbType = SqlDbType.DateTime, Value = DateTime.Now.ToFullSqlString() });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_lastup_date", SqlDbType = SqlDbType.DateTime, Value = DateTime.Now.ToFullSqlString() });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_tarihi", SqlDbType = SqlDbType.DateTime, Value = tarih.ToSqlString() });

            if (gelenHavale)
            {
                prmList.Add(new SqlParameter() { ParameterName = "@cha_tip", SqlDbType = SqlDbType.VarChar, Value = 1 });
                prmList.Add(new SqlParameter() { ParameterName = "@cha_evrak_tip", SqlDbType = SqlDbType.TinyInt, Value = 34 });
            }
            else
            {
                prmList.Add(new SqlParameter() { ParameterName = "@cha_tip", SqlDbType = SqlDbType.VarChar, Value = 0 });
                prmList.Add(new SqlParameter() { ParameterName = "@cha_evrak_tip", SqlDbType = SqlDbType.TinyInt, Value = 35 });
            }

            prmList.Add(new SqlParameter() { ParameterName = "@cha_satir_no", SqlDbType = SqlDbType.Int, Value = satir });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_evrakno_seri", SqlDbType = SqlDbType.NVarChar, Value = seri });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_evrakno_sira", SqlDbType = SqlDbType.Int, Value = sira });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_belge_no", SqlDbType = SqlDbType.VarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_belge_tarih", SqlDbType = SqlDbType.DateTime, Value = tarih.ToSqlString() });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_cari_cins", SqlDbType = SqlDbType.TinyInt, Value = (byte)tip });

            if ((byte)tip == 2)
            {
                prmList.Add(new SqlParameter() { ParameterName = "@cha_grupno", SqlDbType = SqlDbType.TinyInt, Value = 1 });
            }
            else
            {
                prmList.Add(new SqlParameter() { ParameterName = "@cha_grupno", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            }

            prmList.Add(new SqlParameter() { ParameterName = "@cha_kod", SqlDbType = SqlDbType.VarChar, Value = karsiHesapKodu });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_kasa_hizkod", SqlDbType = SqlDbType.VarChar, Value = bankaKodu });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_meblag", SqlDbType = SqlDbType.Float, Value = meblag });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vade", SqlDbType = SqlDbType.VarChar, Value = tarih.Year.ToString("0000") + tarih.Month.ToString("00") + tarih.Day.ToString("00") });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_aciklama", Size = 40, SqlDbType = SqlDbType.VarChar, Value = aciklama });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_srmrkkodu", SqlDbType = SqlDbType.VarChar, Value = srmKodu });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_aratoplam", SqlDbType = SqlDbType.Float, Value = meblag });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_karsisrmrkkodu", SqlDbType = SqlDbType.VarChar, Value = karsiSrm });

            _dbsql.Exec(sb.ToString(), trn, prmList.ToArray());

        }

        public virtual int CharEkle(EvrakTipleri evrakTip, SqlTransaction trn, string evrakSeri, int evrakSira, DateTime evrakTarihi, decimal meblag, decimal[] vergiler, string saticiKodu, string cariKodu, decimal araToplam, string belgeNo, int vade, string aciklama, decimal isk1Tutar, decimal isk2Tutar, decimal isk3Tutar, int cariCins, string kasaKodu, string srmMerkezi, decimal otvTutari)
        {
            string sqlStr = "if exists(SELECT     cha_RECno FROM         CARI_HESAP_HAREKETLERI WHERE     (cha_evrak_tip = @cha_evrak_tip) AND (cha_evrakno_seri = @cha_evrakno_seri) AND (cha_evrakno_sira = @cha_evrakno_sira) AND (cha_satir_no = @cha_satir_no)) delete FROM CARI_HESAP_HAREKETLERI WHERE     (cha_evrak_tip = @cha_evrak_tip) AND (cha_evrakno_seri = @cha_evrakno_seri) AND (cha_evrakno_sira = @cha_evrakno_sira) AND (cha_satir_no = @cha_satir_no);insert into CARI_HESAP_HAREKETLERI (cha_RECid_DBCno,cha_RECid_RECno,cha_SpecRecNo,cha_iptal,cha_fileid,cha_hidden,cha_kilitli,cha_degisti,cha_CheckSum,cha_create_user,cha_create_date,cha_lastup_user,cha_lastup_date,cha_special1,cha_special2,cha_special3,cha_firmano,cha_subeno,cha_tarihi,cha_tip,cha_cinsi,cha_normal_Iade,cha_evrak_tip,cha_satir_no,cha_evrakno_seri,cha_evrakno_sira,cha_belge_no,cha_belge_tarih,cha_cari_cins,cha_kod,cha_kasa_hizmet,cha_kasa_hizkod,cha_d_kurtar,cha_d_cins,cha_d_kur,cha_altd_kur,cha_grupno,cha_meblag,cha_vade,cha_fis_tarih,cha_fis_sirano,cha_ft_iskonto1,cha_ft_iskonto2,cha_ft_iskonto3,cha_ft_iskonto4,cha_ft_iskonto5,cha_ft_iskonto6,cha_ft_masraf1,cha_ft_masraf2,cha_ft_masraf3,cha_ft_masraf4,cha_vergi1,cha_vergi2,cha_vergi3,cha_vergi4,cha_vergi5,cha_vergi6,cha_vergi7,cha_vergi8,cha_vergi9,cha_vergi10,cha_yuvarlama,cha_tpoz,cha_aciklama,cha_trefno,cha_sntck_poz,cha_karsidcinsi,cha_karsid_kur,cha_karsidgrupno,cha_srmrkkodu,cha_reftarihi,cha_odeme_arr1,cha_odeme_arr2,cha_odeme_arr3,cha_odeme_arr4,cha_odeme_arr5,cha_odeme_arr6,cha_odeme_arr7,cha_odeme_arr8,cha_miktari,cha_aratoplam,cha_vergipntr,cha_istisnakodu,cha_ver_tev_carpani,cha_stopaj,cha_savsandesfonu,cha_vergisiz_fl,cha_satici_kodu,cha_mustahsil_borsa,cha_mustahsil_bagkur,cha_mustahsil_diger,cha_HalMSDF,cha_HalHamaliye,cha_HalStopaj,cha_HalKomisyonu,cha_StFonPntr,cha_pos_hareketi,cha_vardiya_tarihi,cha_vardiya_no,cha_vardiya_evrak_ti,cha_HalRusum,cha_HalNavlunTut,cha_HalRehinFuture,cha_HalKomisyon,cha_Vade_Farki_Yuz,cha_karsisrmrkkodu,cha_EXIMkodu,cha_HalRehinSandikmiktari,cha_HalSandikVrMiktar,cha_HalSandikTutari,cha_HalSandikKDVTutari,cha_HalrehinSandikTutari,cha_Tevkifat_turu,cha_ticaret_turu,cha_otvtutari,cha_otvvergisiz_fl,cha_projekodu,cha_sozlesme_DBCno,cha_sozlesme_RECno,cha_yat_tes_kodu,cha_ciro_cari_kodu,cha_oivergisiz_fl,cha_meblag_ana_doviz_icin_gecersiz_fl,cha_meblag_alt_doviz_icin_gecersiz_fl,cha_meblag_orj_doviz_icin_gecersiz_fl,cha_ciroprim_DBCno,cha_ciroprim_RECno,cha_HalHamaliyeKdv,cha_HalHamaliyeVergisiz_fl) values (@cha_RECid_DBCno,@cha_RECid_RECno,@cha_SpecRecNo,@cha_iptal,@cha_fileid,@cha_hidden,@cha_kilitli,@cha_degisti,@cha_CheckSum,@cha_create_user,@cha_create_date,@cha_lastup_user,@cha_lastup_date,@cha_special1,@cha_special2,@cha_special3,@cha_firmano,@cha_subeno,@cha_tarihi,@cha_tip,@cha_cinsi,@cha_normal_Iade,@cha_evrak_tip,@cha_satir_no,@cha_evrakno_seri,@cha_evrakno_sira,@cha_belge_no,@cha_belge_tarih,@cha_cari_cins,@cha_kod,@cha_kasa_hizmet,@cha_kasa_hizkod,@cha_d_kurtar,@cha_d_cins,@cha_d_kur,@cha_altd_kur,@cha_grupno,@cha_meblag,@cha_vade,@cha_fis_tarih,@cha_fis_sirano,@cha_ft_iskonto1,@cha_ft_iskonto2,@cha_ft_iskonto3,@cha_ft_iskonto4,@cha_ft_iskonto5,@cha_ft_iskonto6,@cha_ft_masraf1,@cha_ft_masraf2,@cha_ft_masraf3,@cha_ft_masraf4,@cha_vergi1,@cha_vergi2,@cha_vergi3,@cha_vergi4,@cha_vergi5,@cha_vergi6,@cha_vergi7,@cha_vergi8,@cha_vergi9,@cha_vergi10,@cha_yuvarlama,@cha_tpoz,@cha_aciklama,@cha_trefno,@cha_sntck_poz,@cha_karsidcinsi,@cha_karsid_kur,@cha_karsidgrupno,@cha_srmrkkodu,@cha_reftarihi,@cha_odeme_arr1,@cha_odeme_arr2,@cha_odeme_arr3,@cha_odeme_arr4,@cha_odeme_arr5,@cha_odeme_arr6,@cha_odeme_arr7,@cha_odeme_arr8,@cha_miktari,@cha_aratoplam,@cha_vergipntr,@cha_istisnakodu,@cha_ver_tev_carpani,@cha_stopaj,@cha_savsandesfonu,@cha_vergisiz_fl,@cha_satici_kodu,@cha_mustahsil_borsa,@cha_mustahsil_bagkur,@cha_mustahsil_diger,@cha_HalMSDF,@cha_HalHamaliye,@cha_HalStopaj,@cha_HalKomisyonu,@cha_StFonPntr,@cha_pos_hareketi,@cha_vardiya_tarihi,@cha_vardiya_no,@cha_vardiya_evrak_ti,@cha_HalRusum,@cha_HalNavlunTut,@cha_HalRehinFuture,@cha_HalKomisyon,@cha_Vade_Farki_Yuz,@cha_karsisrmrkkodu,@cha_EXIMkodu,@cha_HalRehinSandikmiktari,@cha_HalSandikVrMiktar,@cha_HalSandikTutari,@cha_HalSandikKDVTutari,@cha_HalrehinSandikTutari,@cha_Tevkifat_turu,@cha_ticaret_turu,@cha_otvtutari,@cha_otvvergisiz_fl,@cha_projekodu,@cha_sozlesme_DBCno,@cha_sozlesme_RECno,@cha_yat_tes_kodu,@cha_ciro_cari_kodu,@cha_oivergisiz_fl,@cha_meblag_ana_doviz_icin_gecersiz_fl,@cha_meblag_alt_doviz_icin_gecersiz_fl,@cha_meblag_orj_doviz_icin_gecersiz_fl,@cha_ciroprim_DBCno,@cha_ciroprim_RECno,@cha_HalHamaliyeKdv,@cha_HalHamaliyeVergisiz_fl);SELECT SCOPE_IDENTITY()";
            List<SqlParameter> prmList = new List<SqlParameter>();
            int[] tipler = CharEvrakTip(evrakTip);

            prmList.Add(new SqlParameter() { ParameterName = "@cha_RECid_DBCno", SqlDbType = SqlDbType.SmallInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_RECid_RECno", SqlDbType = SqlDbType.Int, Value = -1 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_SpecRecNo", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_iptal", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_fileid", SqlDbType = SqlDbType.SmallInt, Value = 51 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_hidden", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_kilitli", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_degisti", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_CheckSum", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_create_user", SqlDbType = SqlDbType.SmallInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_create_date", SqlDbType = SqlDbType.DateTime, Value = evrakTarihi });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_lastup_user", SqlDbType = SqlDbType.SmallInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_lastup_date", SqlDbType = SqlDbType.DateTime, Value = evrakTarihi });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_special1", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_special2", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_special3", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_firmano", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_subeno", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_tarihi", SqlDbType = SqlDbType.DateTime, Value = evrakTarihi });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_tip", SqlDbType = SqlDbType.TinyInt, Value = tipler[0] });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_cinsi", SqlDbType = SqlDbType.TinyInt, Value = tipler[1] });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_normal_Iade", SqlDbType = SqlDbType.TinyInt, Value = tipler[2] });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_evrak_tip", SqlDbType = SqlDbType.TinyInt, Value = tipler[3] });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_satir_no", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_evrakno_seri", SqlDbType = SqlDbType.NVarChar, Value = evrakSeri });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_evrakno_sira", SqlDbType = SqlDbType.Int, Value = evrakSira });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_belge_no", SqlDbType = SqlDbType.NVarChar, Value = belgeNo });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_belge_tarih", SqlDbType = SqlDbType.DateTime, Value = evrakTarihi });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_cari_cins", SqlDbType = SqlDbType.TinyInt, Value = cariCins });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_kod", SqlDbType = SqlDbType.NVarChar, Value = kasaKodu });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_kasa_hizmet", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_kasa_hizkod", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_d_kurtar", SqlDbType = SqlDbType.DateTime, Value = "1899-12-30 00:00:00" });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_d_cins", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_d_kur", SqlDbType = SqlDbType.Float, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_altd_kur", SqlDbType = SqlDbType.Float, Value = 1 });

            if (cariCins == 2)
            {
                prmList.Add(new SqlParameter() { ParameterName = "@cha_grupno", SqlDbType = SqlDbType.TinyInt, Value = 1 });
            }
            else
            {
                prmList.Add(new SqlParameter() { ParameterName = "@cha_grupno", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            }

            prmList.Add(new SqlParameter() { ParameterName = "@cha_meblag", SqlDbType = SqlDbType.Float, Value = meblag });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vade", SqlDbType = SqlDbType.Int, Value = vade });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_fis_tarih", SqlDbType = SqlDbType.DateTime, Value = "1899-12-30 00:00:00" });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_fis_sirano", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ft_iskonto1", SqlDbType = SqlDbType.Float, Value = isk1Tutar });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ft_iskonto2", SqlDbType = SqlDbType.Float, Value = isk2Tutar });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ft_iskonto3", SqlDbType = SqlDbType.Float, Value = isk3Tutar });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ft_iskonto4", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ft_iskonto5", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ft_iskonto6", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ft_masraf1", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ft_masraf2", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ft_masraf3", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ft_masraf4", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vergi1", SqlDbType = SqlDbType.Float, Value = vergiler[0] });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vergi2", SqlDbType = SqlDbType.Float, Value = vergiler[1] });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vergi3", SqlDbType = SqlDbType.Float, Value = vergiler[2] });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vergi4", SqlDbType = SqlDbType.Float, Value = vergiler[3] });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vergi5", SqlDbType = SqlDbType.Float, Value = vergiler[4] });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vergi6", SqlDbType = SqlDbType.Float, Value = vergiler[5] });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vergi7", SqlDbType = SqlDbType.Float, Value = vergiler[6] });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vergi8", SqlDbType = SqlDbType.Float, Value = vergiler[7] });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vergi9", SqlDbType = SqlDbType.Float, Value = vergiler[8] });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vergi10", SqlDbType = SqlDbType.Float, Value = vergiler[9] });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_yuvarlama", SqlDbType = SqlDbType.Float, Value = 0 });

            if (cariCins == 4)
                prmList.Add(new SqlParameter() { ParameterName = "@cha_tpoz", SqlDbType = SqlDbType.TinyInt, Value = 1 });
            else
                prmList.Add(new SqlParameter() { ParameterName = "@cha_tpoz", SqlDbType = SqlDbType.TinyInt, Value = 0 });

            prmList.Add(new SqlParameter() { ParameterName = "@cha_aciklama", SqlDbType = SqlDbType.NVarChar, Value = aciklama });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_trefno", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_sntck_poz", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_karsidcinsi", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_karsid_kur", SqlDbType = SqlDbType.Float, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_karsidgrupno", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_srmrkkodu", SqlDbType = SqlDbType.NVarChar, Value = srmMerkezi });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_reftarihi", SqlDbType = SqlDbType.DateTime, Value = "1899-12-30 00:00:00" });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_odeme_arr1", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_odeme_arr2", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_odeme_arr3", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_odeme_arr4", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_odeme_arr5", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_odeme_arr6", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_odeme_arr7", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_odeme_arr8", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_miktari", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_aratoplam", SqlDbType = SqlDbType.Float, Value = araToplam });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vergipntr", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_istisnakodu", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ver_tev_carpani", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_stopaj", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_savsandesfonu", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vergisiz_fl", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_satici_kodu", SqlDbType = SqlDbType.NVarChar, Value = saticiKodu });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_mustahsil_borsa", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_mustahsil_bagkur", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_mustahsil_diger", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalMSDF", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalHamaliye", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalStopaj", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalKomisyonu", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_StFonPntr", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_pos_hareketi", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vardiya_tarihi", SqlDbType = SqlDbType.DateTime, Value = "1899-12-30 00:00:00" });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vardiya_no", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_vardiya_evrak_ti", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalRusum", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalNavlunTut", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalRehinFuture", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalKomisyon", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_Vade_Farki_Yuz", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_karsisrmrkkodu", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_EXIMkodu", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalRehinSandikmiktari", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalSandikVrMiktar", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalSandikTutari", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalSandikKDVTutari", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalrehinSandikTutari", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_Tevkifat_turu", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ticaret_turu", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_otvtutari", SqlDbType = SqlDbType.Float, Value = otvTutari });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_otvvergisiz_fl", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_projekodu", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_sozlesme_DBCno", SqlDbType = SqlDbType.SmallInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_sozlesme_RECno", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_yat_tes_kodu", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ciro_cari_kodu", SqlDbType = SqlDbType.NVarChar, Value = cariKodu });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_oivergisiz_fl", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_meblag_ana_doviz_icin_gecersiz_fl", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_meblag_alt_doviz_icin_gecersiz_fl", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_meblag_orj_doviz_icin_gecersiz_fl", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ciroprim_DBCno", SqlDbType = SqlDbType.SmallInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_ciroprim_RECno", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalHamaliyeKdv", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@cha_HalHamaliyeVergisiz_fl", SqlDbType = SqlDbType.Bit, Value = false });
            object recid = _dbsql.ExecScalar<object>(sqlStr, trn, prmList.ToArray());
            if (recid != null)
            {
                _dbsql.Exec(string.Format("UPDATE CARI_HESAP_HAREKETLERI SET cha_RECid_RECno=cha_RECno WHERE cha_RECno={0}", recid.ToString()), trn);
                return Convert.ToInt32(recid);
            }
            return -1;
        }

        public virtual int SharEkle(EvrakTipleri evrakTip, SqlTransaction trn, string evrakSeri, int evrakSira, DateTime evrakTarihi, int evrakSatir, string stokKodu, string cariKod, string plasiyerKod, decimal miktar, decimal tutar, int kdvSira, decimal kdvOran, int charRecNo, int girisDepoNo, int cikisDepoNo, decimal isk1Tutar, decimal isk2Tutar, decimal isk3Tutar, string srmMerkezi, int vade)
        {
            string sqlStr = "if exists(SELECT     sth_RECno FROM         STOK_HAREKETLERI WHERE     (sth_evraktip = @sth_evraktip) AND (sth_evrakno_seri = @sth_evrakno_seri) AND (sth_evrakno_sira = @sth_evrakno_sira) AND (sth_satirno = @sth_satirno)) delete FROM STOK_HAREKETLERI WHERE     (sth_evraktip = @sth_evraktip) AND (sth_evrakno_seri = @sth_evrakno_seri) AND (sth_evrakno_sira = @sth_evrakno_sira) AND (sth_satirno = @sth_satirno);insert into STOK_HAREKETLERI (sth_RECid_DBCno,sth_RECid_RECno,sth_SpecRECno,sth_iptal,sth_fileid,sth_hidden,sth_kilitli,sth_degisti,sth_checksum,sth_create_user,sth_create_date,sth_lastup_user,sth_lastup_date,sth_special1,sth_special2,sth_special3,sth_firmano,sth_subeno,sth_tarih,sth_tip,sth_cins,sth_normal_iade,sth_evraktip,sth_evrakno_seri,sth_evrakno_sira,sth_satirno,sth_belge_no,sth_belge_tarih,sth_stok_kod,sth_isk_mas1,sth_isk_mas2,sth_isk_mas3,sth_isk_mas4,sth_isk_mas5,sth_isk_mas6,sth_isk_mas7,sth_isk_mas8,sth_isk_mas9,sth_isk_mas10,sth_sat_iskmas1,sth_sat_iskmas2,sth_sat_iskmas3,sth_sat_iskmas4,sth_sat_iskmas5,sth_sat_iskmas6,sth_sat_iskmas7,sth_sat_iskmas8,sth_sat_iskmas9,sth_sat_iskmas10,sth_pos_satis,sth_cari_cinsi,sth_cari_kodu,sth_cari_grup_no,sth_isemri_gider_kodu,sth_ismerkezi_kodu,sth_plasiyer_kodu,sth_kur_tarihi,sth_har_doviz_cinsi,sth_har_doviz_kuru,sth_alt_doviz_kuru,sth_stok_doviz_cinsi,sth_stok_doviz_kuru,sth_miktar,sth_miktar2,sth_birim_pntr,sth_tutar,sth_iskonto1,sth_iskonto2,sth_iskonto3,sth_iskonto4,sth_iskonto5,sth_iskonto6,sth_masraf1,sth_masraf2,sth_masraf3,sth_masraf4,sth_vergi_pntr,sth_vergi,sth_masraf_vergi_pntr,sth_masraf_vergi,sth_netagirlik,sth_odeme_op,sth_aciklama,sth_sip_recid_dbcno,sth_sip_recid_recno,sth_fat_recid_dbcno,sth_fat_recid_recno,sth_giris_depo_no,sth_cikis_depo_no,sth_malkbl_sevk_tarihi,sth_cari_srm_merkezi,sth_stok_srm_merkezi,sth_fis_tarihi,sth_fis_sirano,sth_vergisiz_fl,sth_maliyet_ana,sth_maliyet_alternatif,sth_maliyet_orjinal,sth_adres_no,sth_parti_kodu,sth_lot_no,sth_kons_recid_dbcno,sth_kons_recid_recno,sth_subesip_recid_dbcno,sth_subesip_recid_recno,sth_vardiya_tarihi,sth_vardiya_no,sth_satistipi,sth_proje_kodu,sth_ihracat_kredi_kodu,sth_exim_kodu,sth_otv_pntr,sth_otv_vergi,sth_bkm_recid_dbcno,sth_bkm_recid_recno,sth_karsikons_recid_dbcno,sth_karsikons_recid_recno,sth_iade_evrak_seri,sth_iade_evrak_sira,sth_diib_belge_no,sth_diib_satir_no,sth_mensey_ulke_tipi,sth_mensey_ulke_kodu,sth_brutagirlik,sth_halrehmiktari,sth_halrehfiyati,sth_halsandikmiktari,sth_halsandikfiyati,sth_halsandikkdvtutari,sth_disticaret_turu,sth_otvtutari,sth_otvvergisiz_fl,sth_direkt_iscilik_1,sth_direkt_iscilik_2,sth_direkt_iscilik_3,sth_direkt_iscilik_4,sth_direkt_iscilik_5,sth_genel_uretim_1,sth_genel_uretim_2,sth_genel_uretim_3,sth_genel_uretim_4,sth_genel_uretim_5,sth_yat_tes_kodu,sth_oiv_pntr,sth_oiv_vergi,sth_oivvergisiz_fl,sth_fiyat_liste_no,sth_fis_tarihi2,sth_fis_sirano2,sth_rez_recid_dbcno,sth_rez_recid_recno) values (@sth_RECid_DBCno,@sth_RECid_RECno,@sth_SpecRECno,@sth_iptal,@sth_fileid,@sth_hidden,@sth_kilitli,@sth_degisti,@sth_checksum,@sth_create_user,@sth_create_date,@sth_lastup_user,@sth_lastup_date,@sth_special1,@sth_special2,@sth_special3,@sth_firmano,@sth_subeno,@sth_tarih,@sth_tip,@sth_cins,@sth_normal_iade,@sth_evraktip,@sth_evrakno_seri,@sth_evrakno_sira,@sth_satirno,@sth_belge_no,@sth_belge_tarih,@sth_stok_kod,@sth_isk_mas1,@sth_isk_mas2,@sth_isk_mas3,@sth_isk_mas4,@sth_isk_mas5,@sth_isk_mas6,@sth_isk_mas7,@sth_isk_mas8,@sth_isk_mas9,@sth_isk_mas10,@sth_sat_iskmas1,@sth_sat_iskmas2,@sth_sat_iskmas3,@sth_sat_iskmas4,@sth_sat_iskmas5,@sth_sat_iskmas6,@sth_sat_iskmas7,@sth_sat_iskmas8,@sth_sat_iskmas9,@sth_sat_iskmas10,@sth_pos_satis,@sth_cari_cinsi,@sth_cari_kodu,@sth_cari_grup_no,@sth_isemri_gider_kodu,@sth_ismerkezi_kodu,@sth_plasiyer_kodu,@sth_kur_tarihi,@sth_har_doviz_cinsi,@sth_har_doviz_kuru,@sth_alt_doviz_kuru,@sth_stok_doviz_cinsi,@sth_stok_doviz_kuru,@sth_miktar,@sth_miktar2,@sth_birim_pntr,@sth_tutar,@sth_iskonto1,@sth_iskonto2,@sth_iskonto3,@sth_iskonto4,@sth_iskonto5,@sth_iskonto6,@sth_masraf1,@sth_masraf2,@sth_masraf3,@sth_masraf4,@sth_vergi_pntr,@sth_vergi,@sth_masraf_vergi_pntr,@sth_masraf_vergi,@sth_netagirlik,@sth_odeme_op,@sth_aciklama,@sth_sip_recid_dbcno,@sth_sip_recid_recno,@sth_fat_recid_dbcno,@sth_fat_recid_recno,@sth_giris_depo_no,@sth_cikis_depo_no,@sth_malkbl_sevk_tarihi,@sth_cari_srm_merkezi,@sth_stok_srm_merkezi,@sth_fis_tarihi,@sth_fis_sirano,@sth_vergisiz_fl,@sth_maliyet_ana,@sth_maliyet_alternatif,@sth_maliyet_orjinal,@sth_adres_no,@sth_parti_kodu,@sth_lot_no,@sth_kons_recid_dbcno,@sth_kons_recid_recno,@sth_subesip_recid_dbcno,@sth_subesip_recid_recno,@sth_vardiya_tarihi,@sth_vardiya_no,@sth_satistipi,@sth_proje_kodu,@sth_ihracat_kredi_kodu,@sth_exim_kodu,@sth_otv_pntr,@sth_otv_vergi,@sth_bkm_recid_dbcno,@sth_bkm_recid_recno,@sth_karsikons_recid_dbcno,@sth_karsikons_recid_recno,@sth_iade_evrak_seri,@sth_iade_evrak_sira,@sth_diib_belge_no,@sth_diib_satir_no,@sth_mensey_ulke_tipi,@sth_mensey_ulke_kodu,@sth_brutagirlik,@sth_halrehmiktari,@sth_halrehfiyati,@sth_halsandikmiktari,@sth_halsandikfiyati,@sth_halsandikkdvtutari,@sth_disticaret_turu,@sth_otvtutari,@sth_otvvergisiz_fl,@sth_direkt_iscilik_1,@sth_direkt_iscilik_2,@sth_direkt_iscilik_3,@sth_direkt_iscilik_4,@sth_direkt_iscilik_5,@sth_genel_uretim_1,@sth_genel_uretim_2,@sth_genel_uretim_3,@sth_genel_uretim_4,@sth_genel_uretim_5,@sth_yat_tes_kodu,@sth_oiv_pntr,@sth_oiv_vergi,@sth_oivvergisiz_fl,@sth_fiyat_liste_no,@sth_fis_tarihi2,@sth_fis_sirano2,@sth_rez_recid_dbcno,@sth_rez_recid_recno);UPDATE STOK_HAREKETLERI SET sth_RECid_RECno=sth_RECno WHERE sth_RECno=SCOPE_IDENTITY();SELECT SCOPE_IDENTITY()";
            List<SqlParameter> prmList = new List<SqlParameter>();
            int[] tipler = SharEvrakTip(evrakTip);

            prmList.Add(new SqlParameter() { ParameterName = "@sth_RECid_DBCno", SqlDbType = SqlDbType.SmallInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_RECid_RECno", SqlDbType = SqlDbType.Int, Value = -1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_SpecRECno", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_iptal", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_fileid", SqlDbType = SqlDbType.SmallInt, Value = 16 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_hidden", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_kilitli", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_degisti", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_checksum", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_create_user", SqlDbType = SqlDbType.SmallInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_create_date", SqlDbType = SqlDbType.DateTime, Value = DateTime.Now });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_lastup_user", SqlDbType = SqlDbType.SmallInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_lastup_date", SqlDbType = SqlDbType.DateTime, Value = DateTime.Now });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_special1", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_special2", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_special3", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_firmano", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_subeno", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_tarih", SqlDbType = SqlDbType.DateTime, Value = evrakTarihi });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_tip", SqlDbType = SqlDbType.TinyInt, Value = tipler[0] });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_cins", SqlDbType = SqlDbType.TinyInt, Value = tipler[1] });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_normal_iade", SqlDbType = SqlDbType.TinyInt, Value = tipler[2] });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_evraktip", SqlDbType = SqlDbType.TinyInt, Value = tipler[3] });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_evrakno_seri", SqlDbType = SqlDbType.NVarChar, Value = evrakSeri });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_evrakno_sira", SqlDbType = SqlDbType.Int, Value = evrakSira });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_satirno", SqlDbType = SqlDbType.Int, Value = evrakSatir });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_belge_no", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_belge_tarih", SqlDbType = SqlDbType.DateTime, Value = evrakTarihi });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_stok_kod", SqlDbType = SqlDbType.NVarChar, Value = stokKodu });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_isk_mas1", SqlDbType = SqlDbType.TinyInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_isk_mas2", SqlDbType = SqlDbType.TinyInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_isk_mas3", SqlDbType = SqlDbType.TinyInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_isk_mas4", SqlDbType = SqlDbType.TinyInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_isk_mas5", SqlDbType = SqlDbType.TinyInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_isk_mas6", SqlDbType = SqlDbType.TinyInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_isk_mas7", SqlDbType = SqlDbType.TinyInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_isk_mas8", SqlDbType = SqlDbType.TinyInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_isk_mas9", SqlDbType = SqlDbType.TinyInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_isk_mas10", SqlDbType = SqlDbType.TinyInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_sat_iskmas1", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_sat_iskmas2", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_sat_iskmas3", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_sat_iskmas4", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_sat_iskmas5", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_sat_iskmas6", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_sat_iskmas7", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_sat_iskmas8", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_sat_iskmas9", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_sat_iskmas10", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_pos_satis", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_cari_cinsi", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_cari_kodu", SqlDbType = SqlDbType.NVarChar, Value = cariKod });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_cari_grup_no", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_isemri_gider_kodu", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_ismerkezi_kodu", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_plasiyer_kodu", SqlDbType = SqlDbType.NVarChar, Value = plasiyerKod });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_kur_tarihi", SqlDbType = SqlDbType.DateTime, Value = "1899-12-30 00:00:00" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_har_doviz_cinsi", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_har_doviz_kuru", SqlDbType = SqlDbType.Float, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_alt_doviz_kuru", SqlDbType = SqlDbType.Float, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_stok_doviz_cinsi", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_stok_doviz_kuru", SqlDbType = SqlDbType.Float, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_miktar", SqlDbType = SqlDbType.Float, Value = miktar });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_miktar2", SqlDbType = SqlDbType.Float, Value = miktar });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_birim_pntr", SqlDbType = SqlDbType.TinyInt, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_tutar", SqlDbType = SqlDbType.Float, Value = tutar });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_iskonto1", SqlDbType = SqlDbType.Float, Value = isk1Tutar });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_iskonto2", SqlDbType = SqlDbType.Float, Value = isk2Tutar });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_iskonto3", SqlDbType = SqlDbType.Float, Value = isk3Tutar });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_iskonto4", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_iskonto5", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_iskonto6", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_masraf1", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_masraf2", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_masraf3", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_masraf4", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_vergi_pntr", SqlDbType = SqlDbType.TinyInt, Value = kdvSira });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_vergi", SqlDbType = SqlDbType.Float, Value = kdvOran });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_masraf_vergi_pntr", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_masraf_vergi", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_netagirlik", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_odeme_op", SqlDbType = SqlDbType.Int, Value = vade });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_aciklama", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_sip_recid_dbcno", SqlDbType = SqlDbType.SmallInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_sip_recid_recno", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_fat_recid_dbcno", SqlDbType = SqlDbType.SmallInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_fat_recid_recno", SqlDbType = SqlDbType.Int, Value = charRecNo });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_giris_depo_no", SqlDbType = SqlDbType.Int, Value = girisDepoNo });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_cikis_depo_no", SqlDbType = SqlDbType.Int, Value = cikisDepoNo });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_malkbl_sevk_tarihi", SqlDbType = SqlDbType.DateTime, Value = evrakTarihi });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_cari_srm_merkezi", SqlDbType = SqlDbType.NVarChar, Value = srmMerkezi });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_stok_srm_merkezi", SqlDbType = SqlDbType.NVarChar, Value = srmMerkezi });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_fis_tarihi", SqlDbType = SqlDbType.DateTime, Value = "1899-12-30 00:00:00" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_fis_sirano", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_vergisiz_fl", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_maliyet_ana", SqlDbType = SqlDbType.Float, Value = tutar });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_maliyet_alternatif", SqlDbType = SqlDbType.Float, Value = tutar });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_maliyet_orjinal", SqlDbType = SqlDbType.Float, Value = tutar });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_adres_no", SqlDbType = SqlDbType.Int, Value = 1 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_parti_kodu", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_lot_no", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_kons_recid_dbcno", SqlDbType = SqlDbType.SmallInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_kons_recid_recno", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_subesip_recid_dbcno", SqlDbType = SqlDbType.SmallInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_subesip_recid_recno", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_vardiya_tarihi", SqlDbType = SqlDbType.DateTime, Value = "1899-12-30 00:00:00" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_vardiya_no", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_satistipi", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_proje_kodu", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_ihracat_kredi_kodu", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_exim_kodu", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_otv_pntr", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_otv_vergi", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_bkm_recid_dbcno", SqlDbType = SqlDbType.SmallInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_bkm_recid_recno", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_karsikons_recid_dbcno", SqlDbType = SqlDbType.SmallInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_karsikons_recid_recno", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_iade_evrak_seri", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_iade_evrak_sira", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_diib_belge_no", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_diib_satir_no", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_mensey_ulke_tipi", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_mensey_ulke_kodu", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_brutagirlik", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_halrehmiktari", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_halrehfiyati", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_halsandikmiktari", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_halsandikfiyati", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_halsandikkdvtutari", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_disticaret_turu", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_otvtutari", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_otvvergisiz_fl", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_direkt_iscilik_1", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_direkt_iscilik_2", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_direkt_iscilik_3", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_direkt_iscilik_4", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_direkt_iscilik_5", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_genel_uretim_1", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_genel_uretim_2", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_genel_uretim_3", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_genel_uretim_4", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_genel_uretim_5", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_yat_tes_kodu", SqlDbType = SqlDbType.NVarChar, Value = "" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_oiv_pntr", SqlDbType = SqlDbType.TinyInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_oiv_vergi", SqlDbType = SqlDbType.Float, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_oivvergisiz_fl", SqlDbType = SqlDbType.Bit, Value = false });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_fiyat_liste_no", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_fis_tarihi2", SqlDbType = SqlDbType.DateTime, Value = "1899-12-30 00:00:00" });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_fis_sirano2", SqlDbType = SqlDbType.Int, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_rez_recid_dbcno", SqlDbType = SqlDbType.SmallInt, Value = 0 });
            prmList.Add(new SqlParameter() { ParameterName = "@sth_rez_recid_recno", SqlDbType = SqlDbType.Int, Value = 0 });
            object sonuc = _dbsql.ExecScalar<object>(sqlStr, trn, prmList.ToArray());
            if (sonuc != null)
                return Convert.ToInt32(sonuc);
            else
                return -1;
        }

        public virtual int MaxEvrakNo(EvrakTipleri tip, String seri, SqlTransaction trn)
        {
            int sira = 1;
            using (Query q = new Query(_dbSystem))
            {
                q.TransAction = trn;
                switch (tip)
                {
                    case EvrakTipleri.AlisFaturasi:
                        q.Add(string.Format("exec sp_executesql N'SELECT     ISNULL(MAX(cha_evrakno_sira),0) + 1 FROM         CARI_HESAP_HAREKETLERI WHERE (cha_evrak_tip = 0) AND (cha_evrakno_seri = ''{0}'')'", seri));
                        break;
                    case EvrakTipleri.SatisFaturasi:
                        q.Add(string.Format("exec sp_executesql N'SELECT     ISNULL(MAX(cha_evrakno_sira),0) + 1 FROM         CARI_HESAP_HAREKETLERI WHERE (cha_evrak_tip = 63) AND (cha_evrakno_seri = ''{0}'')'", seri));
                        break;
                    case EvrakTipleri.GelenHavale:
                        q.Add(string.Format("exec sp_executesql N'SELECT     ISNULL(MAX(cha_evrakno_sira),0) + 1 FROM         CARI_HESAP_HAREKETLERI WHERE (cha_evrak_tip = 34) AND (cha_evrakno_seri = ''{0}'')'", seri));
                        break;
                    case EvrakTipleri.GidenHavale:
                        q.Add(string.Format("exec sp_executesql N'SELECT     ISNULL(MAX(cha_evrakno_sira),0) + 1 FROM         CARI_HESAP_HAREKETLERI WHERE (cha_evrak_tip = 35) AND (cha_evrakno_seri = ''{0}'')'", seri));
                        break;
                }
                sira = q.ExecScaler<int>();
            }
            return sira;
        }

        public virtual decimal SatisFiyat(string stokkod, string carikod, int depono, SqlTransaction trn)
        {
            decimal fiyat = 0;
            using (Query q = new Query(_dbSystem))
            {
                q.TransAction = trn;
                q.Add("select dbo.fn_StokSatisFiyati(@stokkod,(SELECT cari_satis_fk FROM CARI_HESAPLAR WHERE     (cari_kod = @carikod)),@depo)");
                q.Add("@stokkod", SqlDbType.VarChar, stokkod);
                q.Add("@carikod", SqlDbType.VarChar, carikod);
                q.Add("@depo", SqlDbType.Int, depono);
                fiyat = q.ExecScaler<decimal>();
            }
            return fiyat;
        }

        public virtual decimal[] StokKdvBilgileri(string stokkod)
        {
            decimal[] dizi = new decimal[3];
            using (Query q = new Query(_dbSystem))
            {
                q.Add("SELECT     sto_toptan_vergi AS sira, dbo.fn_VergiYuzde(sto_toptan_vergi) AS oran,sto_otvtutar FROM STOKLAR WHERE     (sto_kod = @stokkod)");
                q.Add("@stokkod", SqlDbType.VarChar, stokkod);
                var sonuc = q.ToList(new { sira = 0, oran = 0d, otv = 0d }).FirstOrDefault();
                if (sonuc != null)
                {
                    dizi[0] = Cevir.Parse<decimal>(sonuc.sira);
                    dizi[1] = Cevir.Parse<decimal>(sonuc.oran);
                    dizi[2] = Cevir.Parse<decimal>(sonuc.otv);
                }
            }
            return dizi;
        }

        public virtual Dictionary<int, int> KdvList()
        {
            DataTable dt = _dbsql.Fill("select dbo.fn_VergiYuzde(1) as oran union all select dbo.fn_VergiYuzde(2) union all select dbo.fn_VergiYuzde(3) union all select dbo.fn_VergiYuzde(4) union all select dbo.fn_VergiYuzde(5) union all select dbo.fn_VergiYuzde(6)");
            Dictionary<int, int> sonuc = new Dictionary<int, int>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (!sonuc.ContainsKey(Convert.ToInt32(dt.Rows[i][0])))
                    sonuc.Add(Convert.ToInt32(dt.Rows[i][0]), i + 1);
            }
            return sonuc;
        }

        public virtual bool AddtoTeminci(string kod, string adi, string adi2, string email, string muhasebeKodu, string vergidaire, string vergino, System.Data.SqlClient.SqlTransaction trn)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("if not exists(select cari_RECno from CARI_HESAPLAR where cari_kod= '{0}') begin ");
            sb.Append("insert into CARI_HESAPLAR (cari_RECid_DBCno,cari_RECid_RECno,cari_SpecRECno,cari_iptal,cari_fileid,cari_hidden,cari_kilitli,cari_degisti,cari_checksum,cari_create_user,cari_create_date,cari_lastup_user,cari_lastup_date,cari_special1,cari_special2,cari_special3,cari_kod,cari_unvan1,cari_unvan2,cari_hareket_tipi,cari_tipi,cari_muh_kod,cari_muh_kod1,cari_muh_kod2,cari_doviz_cinsi,cari_doviz_cinsi1,cari_doviz_cinsi2,cari_vade_fark_yuz,cari_vade_fark_yuz1,cari_vade_fark_yuz2,cari_KurHesapSekli,cari_vdaire_adi,cari_vdaire_no,cari_sicil_no,cari_VergiKimlikNo,cari_satis_fk,cari_odeme_cinsi,cari_odeme_gunu,cari_odemeplan_no,cari_opsiyon_gun,cari_cariodemetercihi,cari_fatura_adres_no,cari_sevk_adres_no,cari_banka_tcmb_kod1,cari_banka_tcmb_subekod1,cari_banka_tcmb_ilkod1,cari_banka_hesapno1,cari_banka_tcmb_kod2,cari_banka_tcmb_subekod2,cari_banka_tcmb_ilkod2,cari_banka_hesapno2,cari_banka_tcmb_kod3,cari_banka_tcmb_subekod3,cari_banka_tcmb_ilkod3,cari_banka_hesapno3,cari_EftHesapNum,cari_Ana_cari_kodu,cari_satis_isk_kod,cari_sektor_kodu,cari_bolge_kodu,cari_grup_kodu,cari_temsilci_kodu,cari_muhartikeli,cari_firma_acik_kapal,cari_BUV_tabi_fl,cari_cari_kilitli_flg,cari_etiket_bas_fl,cari_Detay_incele_flg,cari_POS_ongpesyuzde,cari_POS_ongtaksayi,cari_POS_ongIskOran,cari_kaydagiristarihi,cari_KabEdFCekTutar,cari_HalKomYuzdesi,cari_TeslimSuresi,cari_wwwadresi,cari_EMail,cari_CepTel) values (0,-1,0,0,31,0,0,0,0,1,'{1}',1,'{1}','','','','{0}','{2}','',0,1,'{7}','','',0,255,255,25,0,0,1,'{4}','{5}','','',1,0,0,0,0,0,1,1,'','','','','','','','','','','','',1,'','','','','','','',0,0,0,0,0,0,0,0,'1899-12-30',0,0,0,'','{6}','') ");
            sb.Append(";update CARI_HESAPLAR set cari_RECid_RECno=cari_RECno where cari_RECid_RECno=-1 end");

            try
            {
                _dbsql.Exec(string.Format(sb.ToString(), kod, string.Format("{0}-{1}-{2} {3}:{4}:{5}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second), adi, adi2, vergidaire, vergino, email, muhasebeKodu), trn);
                return true;
            }
            catch (Exception ex)
            {
                Logging.GetLog.ErrorLog(ex);
                return false;
            }
        }

        public virtual Dictionary<string, string> AnaCarikodlari()
        {
            DataTable dt = _dbsql.Fill("SELECT     cr.cari_kod,cr.cari_Ana_cari_kodu,(SELECT     cari_unvan1  FROM         CARI_HESAPLAR  WHERE     (cari_kod = cr.cari_Ana_cari_kodu)) as unvan  FROM         CARI_HESAPLAR AS cr WITH (NOLOCK) WHERE     (cari_Ana_cari_kodu <> '')");
            Dictionary<string, string> sonuc = new Dictionary<string, string>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (!sonuc.ContainsKey(dt.Rows[i][0].ToString()))
                    sonuc.Add(dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString() + ";" + dt.Rows[i][2].ToString());
            }
            return sonuc;
        }

        public virtual Dictionary<string, string> CariTemsilcileri()
        {
            DataTable dt = _dbsql.Fill("SELECT     cari_kod,cari_temsilci_kodu FROM CARI_HESAPLAR");
            Dictionary<string, string> sonuc = new Dictionary<string, string>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (!sonuc.ContainsKey(dt.Rows[i][0].ToString()))
                    sonuc.Add(dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString());
            }
            return sonuc;
        }

        //public virtual DataSet AlisFaturaList(DateTime tarih, string cariKodu)
        //{
        //    DataSet ds = new DataSet();

        //    StringBuilder sb = new StringBuilder();
        //    sb.Append("SELECT     cha_RECno,cha_normal_Iade,cha_evrakno_seri, cha_evrakno_sira, cha_belge_tarih, cha_meblag, cha_vergi1, cha_vergi2, cha_vergi3, cha_vergi4, cha_vergi5, cha_vergi6, cha_vergi7,cha_vergi8, cha_vergi9, cha_vergi10, cha_satici_kodu, cha_ciro_cari_kodu, cha_aratoplam, cha_belge_no, cha_vade, cha_aciklama, cha_ft_iskonto1,cha_ft_iskonto2, cha_ft_iskonto3, cha_cari_cins, cha_kod, cha_srmrkkodu");
        //    sb.Append(" FROM         CARI_HESAP_HAREKETLERI WITH (NOLOCK) ");
        //    sb.AppendFormat(" WHERE  (cha_evrak_tip = 3) AND (cha_belge_tarih >= '{0}') AND (cha_ciro_cari_kodu = '{1}') ", tarih.ToSqlString(), cariKodu);

        //    DataTable dt1 = _dbsql.Fill(sb.ToString());
        //    dt1.TableName = "UST";

        //    DataTable dt2 = _dbsql.Fill(string.Format("SELECT sth_evrakno_seri, sth_evrakno_sira, sth_belge_tarih, sth_satirno, sth_stok_kod, sth_cari_kodu, sth_plasiyer_kodu, sth_miktar, sth_tutar, sth_vergi_pntr, sth_vergi,sth_fat_recid_recno, sth_giris_depo_no, sth_cikis_depo_no, sth_iskonto1, sth_iskonto2, sth_iskonto3 FROM STOK_HAREKETLERI  WITH (NOLOCK) WHERE (sth_evraktip = 3) AND (sth_belge_tarih >= '{0}')", tarih.ToSqlString()));
        //    dt1.TableName = "HAREKET";

        //    ds.Tables.Add(dt1);
        //    ds.Tables.Add(dt2);

        //    return ds;
        //}

        //SELECT TOP 1 * FROM STOK_SERINO_TANIMLARI WITH ( NOLOCK , INDEX = NDX_STOK_SERINO_TANIMLARI_02 )  WHERE (chz_serino=N'2443' AND chz_stok_kodu=N'03')

        //SELECT * FROM CIHAZ_HAREKETLERI WITH ( NOLOCK , INDEX = NDX_CIHAZ_HAREKETLERI_03 )  WHERE (ChHar_master_tablo=0 AND ChHar_master_dbcno=0 AND ChHar_master_recno=8 AND ChHar_SeriNo>=N'') ORDER BY ChHar_SeriNo ASC
    }
}
